//
//  SmallDetailKindCollectionCell.m
//  MarianasTrench
//
//  Created by 王晓晨 on 16/3/18.
//  Copyright © 2016年 王爵. All rights reserved.
//

#import "SmallDetailKindCollectionCell.h"

@implementation SmallDetailKindCollectionCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubViews];
        
    }return self;
}

- (void)setCellArrDetailKindModel:(CellArrDetailKindModel *)cellArrDetailKindModel {
    if (_cellArrDetailKindModel != cellArrDetailKindModel) {
        _cellArrDetailKindModel = cellArrDetailKindModel;
    }
    
    [self.picImage HANDLEIMAGE(_cellArrDetailKindModel.coverMiddle)];
    self.titleLabel.text = _cellArrDetailKindModel.title;
    self.introLabel.text = _cellArrDetailKindModel.intro;
    self.introLabel.font = [UIFont systemFontOfSize:15];
    self.introLabel.textColor = [UIColor grayColor];
    CGFloat num = [_cellArrDetailKindModel.playsCounts integerValue];
    if (num > 10000) {
        self.playsCountLabel.text = [NSString stringWithFormat:@"▷%.1f万", num / 10000.0];
    }
    else {
        self.playsCountLabel.text = [NSString stringWithFormat:@"▷%.f", num];
    }
    self.playsCountLabel.font = [UIFont systemFontOfSize:11];
    self.tracks.text = [NSString stringWithFormat:@"🎵%@集",_cellArrDetailKindModel.tracks];
    self.tracks.font = [UIFont systemFontOfSize:11];
}

- (void)createSubViews {
    self.picImage = [[UIImageView alloc] init];
    [self.contentView addSubview:_picImage];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_titleLabel];
    
    self.introLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_introLabel];
    
    self.playsCountLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_playsCountLabel];
    
    self.tracks = [[UILabel alloc] init];
    [self.contentView addSubview:_tracks];
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    _picImage.frame = CGRectMake(10, 5, CELLHEIGHT - 10, CELLHEIGHT - 10);
    
    _titleLabel.frame = CGRectMake(20 + _picImage.frame.size.width, 5, CELLWIDTH / 3 * 2, CELLHEIGHT / 3);
    
    _introLabel.frame = CGRectMake(_titleLabel.frame.origin.x, 10 + _titleLabel.frame.size.height, _titleLabel.frame.size.width, _titleLabel.frame.size.height / 4 * 3);
    
    _playsCountLabel.frame = CGRectMake(_introLabel.frame.origin.x, 5 + _introLabel.frame.origin.y + _introLabel.frame.size.height, 60, 15);
    
    _tracks.frame = CGRectMake(_playsCountLabel.frame.origin.x + _playsCountLabel.frame.size.width +  5, _playsCountLabel.frame.origin.y, 60, 15);
}

@end
